package com.qiuyang.controller;

import com.qiuyang.pojo.Blog;
import com.qiuyang.service.BlogService;
import com.qiuyang.service.TagService;
import com.qiuyang.service.TypeService;
import com.qiuyang.service.show.ShowBlogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;
import java.util.Map;

@Controller
public class ShowBlogController {

    @Autowired
    private ShowBlogService showBlogService;

    @Autowired
    private BlogService blogService;

    @Autowired
    private TypeService typeService;

    @Autowired
    private TagService tagService;

    @GetMapping("/")
    public String index(Model model){
        model.addAttribute("recommend",showBlogService.blogRecommed());
        model.addAttribute("blog",showBlogService.findAllBlog());
        model.addAttribute("count",showBlogService.countBlog());
        return "blog/index";
    }

    @RequestMapping("/blog/{id}")
    public String showBlog(@PathVariable Long id, Model model){
        showBlogService.insertViews(id);
        model.addAttribute("info", showBlogService.showBlog(id));
        return "blog/info";
    }

    @RequestMapping("/list/{pageNum}")
    public String listBlog(@PathVariable("pageNum") int pageNum,Model model){
        model.addAttribute("list",showBlogService.findBlogAndList(pageNum,3));
        return "blog/list";
    }

    @RequestMapping("/findByTitle/{pageNum}")
    public String bytitle(@PathVariable("pageNum") int pageNum,String title,Model model){
        model.addAttribute("list",showBlogService.findBlogTitle(title,pageNum,3));
        return "blog/list";
    }

}
